package com.fcscs.ecms.service.impl;

import java.util.Date;

import org.apache.james.mime4j.field.datetime.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fcscs.cservice.ws.schema.dndservice.DndInfo;
import com.fcscs.ecms.dao.ECMSGuestRequestDao;
import com.fcscs.ecms.domain.GuestRequest;
import com.fcscs.ecms.service.ECMSDndManager;

/**
 * @author pvttinh
 * 
 */

@Service("ecmsDndManager")
public class ECMSDndManagerImpl implements ECMSDndManager {

	@Autowired
	private ECMSGuestRequestDao ecmsGuestRequestDao;

	@Override
	public DndInfo getDndInfo(long orgId, long propertyId, long guestProfileId,
			long reservationId) throws Exception {
		// TODO Auto-generated method stub
		DndInfo dndInfo = new DndInfo();
		try{
			GuestRequest gr = this.ecmsGuestRequestDao.findBy((int)orgId, (int)propertyId, (int)guestProfileId, (int)reservationId, "DND").get(0);
			dndInfo.setRequestId(gr.getId());
			dndInfo.setDndStatus(gr.getRequestStatus());
		}catch (Exception e) {
			// TODO: handle exception
			throw new Exception("Dnd.MANAGER.getDndInfo() - " + e.getMessage());
		}
		
		return dndInfo;
	}

	@Override
	public DndInfo setDndInfo(DndInfo dndInfo, long fcsUserId) throws Exception {
		// TODO Auto-generated method stub
		try{
			GuestRequest gr = this.ecmsGuestRequestDao.get((int)dndInfo.getRequestId());
			
			gr.setRequestStatus(dndInfo.getDndStatus());
			gr.setUpdated(new Date());
			gr.setUpdatedBy((int)fcsUserId);			
			gr.setSource("i-Guest");
			this.ecmsGuestRequestDao.update(gr);
		}catch (Exception e) {
			// TODO: handle exception
			throw new Exception("Dnd.MANAGER.setDndInfo() - " + e.getMessage());
		}
		
		return dndInfo;
	}
}
